package org.cuckoos.android.domain;

/**
 * 飞鸽的命令
 * 
 * @author bugu
 * 
 */
public class Command {
	private String version = Constant.DEFAULT_VERSION;

	private int packetId = (int) System.currentTimeMillis();

	private User user;

	private int command;

	private String msg;
	
//	private String ip;

	

	public Command(){}
	
	public Command(User user, int command) {
		super();
		this.user = user;
		this.command = command;
//		this.ip = user.getIp();
	}

	public Command(User user, int command, String msg) {
		super();
		this.user = user;
		this.command = command;
		this.msg = msg;
//		this.ip = user.getIp();
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public int getPacketId() {
		return packetId;
	}

	public void setPacketId(int packetId) {
		this.packetId = packetId;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public int getCommand() {
		return command;
	}

	public void setCommand(int command) {
		this.command = command;
	}

	public void fromString(String command) {
		String[] split = command.split(Constant.SPLIT);
		this.version = split[0];
		this.packetId = Integer.parseInt(split[1]);
		User u = new User(split[2], split[3]);
		this.user = u;
		this.command = Integer.parseInt(split[4]);
		if (split.length >= 6) {
			this.msg = split[5];
		}
	}

	public String toString() {
		return this.version + Constant.SPLIT + this.packetId + Constant.SPLIT
				+ this.user.getName() + Constant.SPLIT + this.user.getHost()
				+ Constant.SPLIT + this.command + Constant.SPLIT
				+ (this.msg == null ? "" : this.msg);
	}
	
//	public String getIp() {
//		return ip;
//	}
//
//	public void setIp(String ip) {
//		this.ip = ip;
//	}
}
